YouTube Data APIの認可フロー
from client_secret
YouTube Data APIの認可フロー
YouTube Data APIの認可フローはOAuth2を基本としているが、テレビ用セットトップボックスなど限定された入力機能しか持たないデバイスのためのフローも用意されている。
Server-side Web Application
Client-side Web Application
Installed Apps
https://developers.google.com/youtube/v3/guides/auth/installed-apps
authorization codeを得る
エンドポイントは https://accounts.google.com/o/oauth2/v2/auth
ユーザーはブラウザなどのユーザーエージェントによりAuthorization URLにGETメソッドでアクセスさせられる
ユーザーは認可するとredirect_uriにアクセスさせられる
この段階ではclient_secretは必要ない。そもそもURLのパラメータ部に入れるべき情報ではない。
authorization codeの窃取に対抗するため、code_challengeが推奨されている
code_challenge_methodがplainの場合は認可エンドポイントからのレスポンスの窃取に対抗できる。
code_challenge_methodがS256の場合はさらに認可エンドポイントへのリクエストリクエストの窃取にも対抗できる。
Android, iOS, UWPではcustom URI schemeでブラウザから情報を受け取ることが想定されている。
MacOS, Linux, Windows desktopアプリではloopbck IP address経由でブラウザから情報を受け取ることが想定されている。
authorization codeをaccess_tokenとrefresh_tokenに引き換える
エンドポイントは https://oauth2.googleapis.com/token
client_secreetが必要
code_challengeを使っている場合はcode_verifierも必要
grant_typeはauthorization_code
Devices
https://developers.google.com/youtube/v3/guides/auth/devices
デバイスは数字パッドによる入力機能だけを持つ
ユーザーはスマートフォンなどブラウザが使える環境を用意する
user_codeとverification_urlとdevice_codeを得る
エンドポイントは https://oauth2.googleapis.com/device/code
client_idとscopeだけで得られる
ユーザーはverification_urlにアクセスする
ブラウザからuser_codeを入力する
https://www.google.com/device
https://scrapbox.io/files/6018c9d7bfb12f001f507f34.png
デバイスがポーリングによりaccess_tokenとrefresh_tokenの取得を待つ
device_code, client_id, client_secret, grant_typeが必要
grant_typeはurn:ietf:params:oauth:grant-type:device_code
エンドポイントは https://oauth2.googleapis.com/token